import socket

if __name__ == '__main__':
    s = socket.socket(family=socket.AF_INET, type=socket.SOCK_STREAM)
    s.bind(('0.0.0.0', 80))

    buffer_size = 1024
    while True:
        s.listen(5)

        # 得到链接的socket   阻塞等待
        sock, addr = s.accept()

        # 接受到发来的数据
        res = sock.recv(buffer_size).decode('UTF-8')
        print(res)

        # 发送数据给客户端 http 协议
        sock.sendall(b'HTTP/1.0 200 OK \r\n \r\n <H1>hi zhang</H1>')

        # 关闭socket链接
        sock.close()

